// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Serverless.Fluent;
using Elastic.Clients.Elasticsearch.Serverless.Serialization;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.Serverless.MachineLearning;

public sealed partial class Definition
{
	/// <summary>
	/// <para>
	/// Collection of preprocessors
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("preprocessors")]
	public ICollection<Elastic.Clients.Elasticsearch.Serverless.MachineLearning.Preprocessor>? Preprocessors { get; set; }

	/// <summary>
	/// <para>
	/// The definition of the trained model.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("trained_model")]
	public Elastic.Clients.Elasticsearch.Serverless.MachineLearning.TrainedModel TrainedModel { get; set; }
}

public sealed partial class DefinitionDescriptor : SerializableDescriptor<DefinitionDescriptor>
{
	internal DefinitionDescriptor(Action<DefinitionDescriptor> configure) => configure.Invoke(this);

	public DefinitionDescriptor() : base()
	{
	}

	private ICollection<Elastic.Clients.Elasticsearch.Serverless.MachineLearning.Preprocessor>? PreprocessorsValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.MachineLearning.PreprocessorDescriptor PreprocessorsDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.MachineLearning.PreprocessorDescriptor> PreprocessorsDescriptorAction { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.MachineLearning.PreprocessorDescriptor>[] PreprocessorsDescriptorActions { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.MachineLearning.TrainedModel TrainedModelValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.MachineLearning.TrainedModelDescriptor TrainedModelDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.MachineLearning.TrainedModelDescriptor> TrainedModelDescriptorAction { get; set; }

	/// <summary>
	/// <para>
	/// Collection of preprocessors
	/// </para>
	/// </summary>
	public DefinitionDescriptor Preprocessors(ICollection<Elastic.Clients.Elasticsearch.Serverless.MachineLearning.Preprocessor>? preprocessors)
	{
		PreprocessorsDescriptor = null;
		PreprocessorsDescriptorAction = null;
		PreprocessorsDescriptorActions = null;
		PreprocessorsValue = preprocessors;
		return Self;
	}

	public DefinitionDescriptor Preprocessors(Elastic.Clients.Elasticsearch.Serverless.MachineLearning.PreprocessorDescriptor descriptor)
	{
		PreprocessorsValue = null;
		PreprocessorsDescriptorAction = null;
		PreprocessorsDescriptorActions = null;
		PreprocessorsDescriptor = descriptor;
		return Self;
	}

	public DefinitionDescriptor Preprocessors(Action<Elastic.Clients.Elasticsearch.Serverless.MachineLearning.PreprocessorDescriptor> configure)
	{
		PreprocessorsValue = null;
		PreprocessorsDescriptor = null;
		PreprocessorsDescriptorActions = null;
		PreprocessorsDescriptorAction = configure;
		return Self;
	}

	public DefinitionDescriptor Preprocessors(params Action<Elastic.Clients.Elasticsearch.Serverless.MachineLearning.PreprocessorDescriptor>[] configure)
	{
		PreprocessorsValue = null;
		PreprocessorsDescriptor = null;
		PreprocessorsDescriptorAction = null;
		PreprocessorsDescriptorActions = configure;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The definition of the trained model.
	/// </para>
	/// </summary>
	public DefinitionDescriptor TrainedModel(Elastic.Clients.Elasticsearch.Serverless.MachineLearning.TrainedModel trainedModel)
	{
		TrainedModelDescriptor = null;
		TrainedModelDescriptorAction = null;
		TrainedModelValue = trainedModel;
		return Self;
	}

	public DefinitionDescriptor TrainedModel(Elastic.Clients.Elasticsearch.Serverless.MachineLearning.TrainedModelDescriptor descriptor)
	{
		TrainedModelValue = null;
		TrainedModelDescriptorAction = null;
		TrainedModelDescriptor = descriptor;
		return Self;
	}

	public DefinitionDescriptor TrainedModel(Action<Elastic.Clients.Elasticsearch.Serverless.MachineLearning.TrainedModelDescriptor> configure)
	{
		TrainedModelValue = null;
		TrainedModelDescriptor = null;
		TrainedModelDescriptorAction = configure;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (PreprocessorsDescriptor is not null)
		{
			writer.WritePropertyName("preprocessors");
			writer.WriteStartArray();
			JsonSerializer.Serialize(writer, PreprocessorsDescriptor, options);
			writer.WriteEndArray();
		}
		else if (PreprocessorsDescriptorAction is not null)
		{
			writer.WritePropertyName("preprocessors");
			writer.WriteStartArray();
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.MachineLearning.PreprocessorDescriptor(PreprocessorsDescriptorAction), options);
			writer.WriteEndArray();
		}
		else if (PreprocessorsDescriptorActions is not null)
		{
			writer.WritePropertyName("preprocessors");
			writer.WriteStartArray();
			foreach (var action in PreprocessorsDescriptorActions)
			{
				JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.MachineLearning.PreprocessorDescriptor(action), options);
			}

			writer.WriteEndArray();
		}
		else if (PreprocessorsValue is not null)
		{
			writer.WritePropertyName("preprocessors");
			JsonSerializer.Serialize(writer, PreprocessorsValue, options);
		}

		if (TrainedModelDescriptor is not null)
		{
			writer.WritePropertyName("trained_model");
			JsonSerializer.Serialize(writer, TrainedModelDescriptor, options);
		}
		else if (TrainedModelDescriptorAction is not null)
		{
			writer.WritePropertyName("trained_model");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.MachineLearning.TrainedModelDescriptor(TrainedModelDescriptorAction), options);
		}
		else
		{
			writer.WritePropertyName("trained_model");
			JsonSerializer.Serialize(writer, TrainedModelValue, options);
		}

		writer.WriteEndObject();
	}
}